package com.test40_JDBC.util;

import java.sql.Connection;
import java.sql.DriverManager;

public class JDBCUtil {
    public static final String DRIVER = "com.mysql.cj.jdbc.Driver"; // 数据库驱动程序
    public static final String URL = "jdbc:mysql://localhost:3306/yootk";   // 连接地址
    public static final String USERNAME = "root";   // 用户名
    public static final String PASSWORD = "root520";    // 密码

    private JDBCUtil() {
    }

    /**
     * 获取连接
     */
    public static Connection getConnection() throws Exception {
        Class.forName(DRIVER);
        Connection conn = DriverManager.getConnection(URL, USERNAME, PASSWORD);
        return conn;
    }

    /**
     * 关闭连接
     */
    public static void closeConnection(Connection conn) throws Exception {
        if (conn != null) {
            conn.close();
        }
    }
}
